// $_FILEHEADER_BEGIN ***************************
// 版权声明:Timer
// Copyright © 2012 - Timer All Rights Reserved
// 文件名称: MeStatue.m
// 创建日期: 15/11/29
// 创 建 人: 甄鑫
// 文件说明: <#content#>
// $_FILEHEADER_END ******************************


#import "MeStatus.h"

#define kLoginKey       @"kLoginKey"
#define kVerifyPhoneKey @"kVerifyPhoneKey"

#define kWXAutoToken    @"kWXAutoToken"
@implementation MeStatus
DEF_SINGLETON(MeStatus)

- (USER_ACCOUNT_STATUS)userAccountStatus
{
    BOOL isHaveLoginKey = [self getLoginKey].isNotEmpty;
    BOOL isHavePhoneKey = [self getVerifyPhoneKey].isNotEmpty;
    if (isHaveLoginKey && isHavePhoneKey) {
        return USER_ACCOUNT_STATUS_VERIFY;
    }
    if (isHaveLoginKey && !isHavePhoneKey) {
        return USER_ACCOUNT_STATUS_LOGIN;
    }
    if (!isHaveLoginKey && !isHavePhoneKey){
        return USER_ACCOUNT_STATUS_UN_LOGIN;
    }
    return USER_ACCOUNT_STATUS_UN_LOGIN;
}
#pragma mark - **************** setter & getter & save

/**
 *  退出登录状态
 */
- (void)removeUserAccount{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [[AFHTTPResponseSerializer alloc] init];
    [manager GET:[NSString stringWithFormat:@"%@/passport/applogout.json",SERVICE_ADRESS] parameters:nil success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
        
    } failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {
        
    }];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:kLoginKey];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:kVerifyPhoneKey];
    [[NSUserDefaults standardUserDefaults]synchronize];

}

// 用户登录key
- (void)saveLoginKey:(NSString *)loginKey
{
    [[NSUserDefaults standardUserDefaults]setObject:loginKey forKey:kLoginKey];
    [[NSUserDefaults standardUserDefaults]synchronize];
}

- (NSString *)getLoginKey
{
    NSString * loginKey = [[NSUserDefaults standardUserDefaults]objectForKey:kLoginKey];
    return loginKey;
}
// 手机验证
- (void)saveVerifyPhoneKey:(NSString *)verifyPhoneKey
{
    [[NSUserDefaults standardUserDefaults]setObject:verifyPhoneKey forKey:kVerifyPhoneKey];
    [[NSUserDefaults standardUserDefaults]synchronize];
}

- (NSString *)getVerifyPhoneKey
{
    NSString * verifyPhoneKey = [[NSUserDefaults standardUserDefaults]objectForKey:kVerifyPhoneKey];
    return verifyPhoneKey;
}
// wx验证
- (void)saveWXAuthToken:(NSString *)wxAuthToken
{
    [[NSUserDefaults standardUserDefaults]setObject:wxAuthToken forKey:kWXAutoToken];
    [[NSUserDefaults standardUserDefaults]synchronize];
}

- (NSString *)getWXAuthToken
{
    NSString * loginKey = [[NSUserDefaults standardUserDefaults]objectForKey:kWXAutoToken];
    return loginKey;
}


- (void)save
{
    
}
- (void)remove
{
    
}
@end
